package com.jt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

@Component
@Aspect
public class UserAOP {
    Map map=new HashMap();
    @Pointcut("@annotation(com.jt.anno.Cache)")
    public void pointcut(){}
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint){
        try {
            Object proceed = joinPoint.getArgs()[0];
            if (map.get(proceed)!=null){
                System.out.println(map.get(proceed));
                return map.get(proceed);
            }else{
                map.put(proceed, proceed+"我是缓存");
                Object proceed1 = joinPoint.proceed();
                return proceed1;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }
}
